import 'dart:io';

import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

import '../utils/image_utils.dart';

class CameraServicePlugin {
  static const _channel = MethodChannel('camera_plugin');

  static Future<String?> takePicture() async {
    try {
      final result = await _channel.invokeMethod<String>('takePicture') ?? "";
      print("result:$result");
      final directory = await getApplicationDocumentsDirectory();
      String path = '${directory.path}/headImage${DateTime.now().toString()}.jpg'; // 设置保存的文件路径
      await ImageUtils.saveImage(File(result), path);
      return path;
    } catch (e) {
      print("拍照失败: $e");
      return null;
    }
  }
}
